package cn.stylefeng.guns.modular.manager.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.manager.entity.FlowCommissionManagement;
import cn.stylefeng.guns.modular.manager.entity.FlowStoreRegionPrice;
import cn.stylefeng.guns.modular.manager.mapper.FlowCommissionManagementMapper;
import cn.stylefeng.guns.modular.manager.mapper.FlowStoreRegionPriceMapper;
import cn.stylefeng.guns.modular.manager.model.params.FlowCommissionManagementParam;
import cn.stylefeng.guns.modular.manager.model.params.FlowStoreRegionPriceParam;
import cn.stylefeng.guns.modular.manager.model.result.FlowCommissionManagementResult;
import cn.stylefeng.guns.modular.manager.model.result.FlowStoreRegionPriceResult;
import cn.stylefeng.guns.modular.manager.service.FlowCommissionManagementService;
import cn.stylefeng.guns.modular.manager.service.FlowStoreRegionPriceService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

@Service
public class FlowCommissionManagementServiceImpl extends ServiceImpl<FlowCommissionManagementMapper, FlowCommissionManagement> implements FlowCommissionManagementService {
    @Override
    public void add(FlowCommissionManagementParam param) {
        FlowCommissionManagement entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(FlowCommissionManagementParam param) {
        this.removeById(getKey(param));
    }

    @Override
    public void update(FlowCommissionManagementParam param) {
        FlowCommissionManagement oldEntity = getOldEntity(param);
        FlowCommissionManagement newEntity = getEntity(param);


        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public FlowCommissionManagementResult findBySpec(FlowCommissionManagementParam param) {
        return null;
    }

    @Override
    public List<FlowCommissionManagementResult> findListBySpec(FlowCommissionManagementParam param) {
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(FlowCommissionManagementParam param) {
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    private FlowCommissionManagement getEntity(FlowCommissionManagementParam param) {
        FlowCommissionManagement entity = new FlowCommissionManagement();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

    private Serializable getKey(FlowCommissionManagementParam param){
        return param.getCommissionId();
    }

    private FlowCommissionManagement getOldEntity(FlowCommissionManagementParam param) {
        return this.getById(getKey(param));
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }
}
